﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Gencode.Controls.CollapsibleControl;

namespace Personalplaner.Modules.Dienstplan
{
    [ToolboxItem(false)]
    public partial class PlanSelect : CollapsibleItem
    {
        DataView m_activePlan;
        DiensplanSelector controler;

		//->
		public DiensplanSelector Controler
		{
			get
			{
				return controler;
			}
			set
			{
				controler = value;
			}
		}
		public PlanSelect()
		{
			InitializeComponent();

			
		}

		private void PlanSelect_Load(object sender, EventArgs e)
		{
			if (!this.DesignMode)
				FillCombo();
		}
		//<-

        public PlanSelect(DiensplanSelector controler)
            : base("Plan")
        {
            this.controler = controler;
            InitializeComponent();
			//FillCombo();
        }

        private void FillCombo()
        {
            m_activePlan = Gencode.PrsCommon.Data.Plan.PlanData.GetActivePlannames(Verwaltung.Mandant, true);
            comboPlan.DataSource = m_activePlan;
            comboPlan.DisplayMember = "Name";
        }

        /// <summary>
        /// Selects te plan with the given planid
        /// </summary>
        /// <param name="planid">PlanID</param>
        public void SetComboPlanIndex(int planid)
        {
            for (int i = 0; i < m_activePlan.Count; i++)
            {
                if (!string.IsNullOrEmpty(m_activePlan[i].Row["PlanID"].ToString()))
                {
                    if (int.Parse(m_activePlan[i].Row["planid"].ToString()) == planid)
                    {
                        comboPlan.SelectedIndex = i;
                        i = m_activePlan.Count;
                    }
                }
            }
        }

        public int getComboPlanIndex()
        {
            return comboPlan.SelectedIndex;
        }

        private void comboPlan_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.comboPlan.SelectedIndex > 0)
            {
                controler.PartnerContent.TabPage(int.Parse(m_activePlan[comboPlan.SelectedIndex].Row["PlanID"].ToString()));
                controler.PartnerView.Focus();
            }
        }

        public void SetComboPlan()
        {
            m_activePlan = Gencode.PrsCommon.Data.Plan.PlanData.GetActivePlannames(Verwaltung.Mandant, true);
            comboPlan.DataSource = m_activePlan;
            comboPlan.DisplayMember = "Name";
        }
    }
}
